<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

declare(strict_types=1);

namespace App\JsonRpc;

use App\Repository\CouponRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\CouponServiceInterface;

/**
 * @RpcService(name="Activity::CouponService", protocol="jsonrpc", server="jsonrpc")
 */
class CouponService extends BaseService implements CouponServiceInterface
{
    public function init()
    {
        $this->repository = CouponRepository::getInstance();
    }

    public function index(array $condition, array $field, int $page, int $size): array
    {
        if(!empty($condition['name'])){
            $condition[] = ['name','like','%'.$condition['name'].'%'];
            unset($condition['name']);
        }
        return parent::index($condition, $field, $page, $size);
    }

    /**
     * Notes: C端领券中心
     * Author: Bruce.z
     * DateTime: 2022/9/7 16:37
     * @param int $page
     * @param int $size
     * @return array
     */
    public function appIndex(int $page, int $size):array
    {
        return $this->repository->appIndex( $page, $size);
    }

    /**
     * Notes: 更新状态
     * Author: Bruce.z
     * DateTime: 2022/9/15 13:37
     * @param array $ids
     * @param int $status
     * @return mixed
     */
    public function updateStatus(array $ids, int $status)
    {
        return $this->repository->updateStatus($ids, $status);
    }

}
